﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class DAO_NgheNghiep
    {
        private DataServices data = new DataServices();
        public DataTable getAllNgheNghiep()
        {
            try
            {
                String sql = "SELECT * FROM " + DTO_NgheNghiep.TB_Name;
                return data.executeGetDataTable(sql);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        public bool insertNN(DTO_NgheNghiep ngheNghiep)
        {
            bool result = false;
            try
            {
                String sql = "INSERT INTO " + DTO_NgheNghiep.TB_Name
                                    + " ( " + DTO_NgheNghiep.TENNGHENGHIEP + " ) VALUES (@" + DTO_NgheNghiep.TENNGHENGHIEP + " ) ";
                SqlParameter p1 = new SqlParameter(DTO_NgheNghiep.TENNGHENGHIEP, ngheNghiep.TenNgheNghiep);
                result = data.executeUpdate(sql, p1);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }

            return result;
        }

        public bool updateNN(DTO_NgheNghiep ngheNghiep)
        {
            bool result = false;
            try
            {
                String sql = "UPDATE " + DTO_NgheNghiep.TB_Name
                                    + " SET " + DTO_NgheNghiep.TENNGHENGHIEP + " =@" + DTO_NgheNghiep.TENNGHENGHIEP
                                    + " WHERE " + DTO_NgheNghiep.MANGHENGHIEP + " =@" + DTO_NgheNghiep.MANGHENGHIEP;
                SqlParameter p1 = new SqlParameter(DTO_NgheNghiep.TENNGHENGHIEP, ngheNghiep.TenNgheNghiep);
                SqlParameter p2 = new SqlParameter(DTO_NgheNghiep.MANGHENGHIEP, ngheNghiep.MaNgheNghiep);
                result = data.executeUpdate(sql, p1, p2);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }

            return result;
        }
        public bool deleteNN(DTO_NgheNghiep ngheNghiep)
        {
            bool result = false;
            try
            {
                String sql = "deleteNgheNghiep";
                SqlParameter p1 = new SqlParameter(DTO_NgheNghiep.MANGHENGHIEP, ngheNghiep.MaNgheNghiep);
                result = data.updateFormProcedure(sql, p1);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }

            return result;
        }

        public DataTable getNNByName(string name)
        {
            try
            {
                String sql = "SELECT * FROM " + DTO_NgheNghiep.TB_Name + " WHERE "
                                    + DTO_NgheNghiep.TENNGHENGHIEP + " LIKE @" + DTO_NgheNghiep.TENNGHENGHIEP;
                SqlParameter p1 = new SqlParameter(DTO_NgheNghiep.TENNGHENGHIEP, "%" + name + "%");
                return data.executeGetDataTable(sql, p1);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
    }
}
